#include "tx_api.h"
#include "main.h"

/* Private defines -----------------------------------------------------------*/
#define TX_APP_STACK_SIZE 512 * 2
#define TX_APP_MEM_POOL_SIZE 1024 * 2

static UCHAR tx_byte_pool_buffer[TX_APP_MEM_POOL_SIZE] __attribute__((aligned(4)));
static TX_BYTE_POOL tx_app_byte_pool;

TX_THREAD tx_app_thread;
void task0(ULONG thread_input);
extern uint32_t _tx_timer_system_clock;

void task0(ULONG thread_input)
{

	while (1)
	{
		printf_("task0 run  \r\n");
		tx_thread_sleep(500);
		HAL_GPIO_WritePin(GPIOC, LED_Pin, GPIO_PIN_SET);
		tx_thread_sleep(50);
		HAL_GPIO_WritePin(GPIOC, LED_Pin, GPIO_PIN_RESET);
		tx_thread_sleep(50);
	}
}

void task1(ULONG thread_input)
{

	while (1)
	{
		printf_("task1 run.\r\n");
		tx_thread_sleep(100);
	}
}

/**
 * @brief  Define the initial system.
 * @param  first_unused_memory : Pointer to the first unused memory
 * @retval None
 */
VOID tx_application_define(VOID *first_unused_memory)
{
	tx_byte_pool_create(&tx_app_byte_pool, "Tx App memory pool", tx_byte_pool_buffer, TX_APP_MEM_POOL_SIZE);

	CHAR *pointer;

	/* Allocate the stack for task0  */
	tx_byte_allocate(&tx_app_byte_pool, (VOID **)&pointer, TX_APP_STACK_SIZE, TX_NO_WAIT);

	/* Create task0.  */
	tx_thread_create(&tx_app_thread, "task0", task0, 0, pointer,
					 TX_APP_STACK_SIZE, 1, 1,
					 TX_NO_TIME_SLICE, TX_AUTO_START);

	// printf("thredx task creat ok  start.\r\n");
}

void tasks_example()
{
	// printf("task_run.\r\n");

	tx_kernel_enter();
	//	printf("ok22.\r\n");
	while (1)
	{
	}
}
